/**
 * @file: hooks/useSuer 用户中心对象hooks
 * @author: v_caihongxing
 */

import {useCallback} from 'react';
import {useDispatch, useSelector} from 'react-redux';
import {setMenuList} from '@/redux/menu';
import {getMenuList as getMenuListApi} from '@/api/home';

const useUser = () => {
    const menuList = useSelector((state: any) => state.menu.menuList);
    const dispatch = useDispatch();

    // 获取用户菜单
    const getMenuList = useCallback(async () => {
        // 模板项目使用mock模拟获取用户详情，可参考使用
        const res = await getMenuListApi();
        dispatch(setMenuList(res.data));
    }, [dispatch]);

    return {
        menuList, // 菜单列表
        getMenuList, // 获取路由信息
    };
};

export default useUser;
